<?php

require_once(DAEMONE_HOME.'/config/database.php');

function get_connection() 
{
	global $config;
	global $connection;
	$connection = mysql_connect($config['db']['host'],$config['db']['username'],$config['db']['password']);
	if (!$connection)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db($config['db']['database'], $connection);
	return $connection;
}

function execute_query($sql)
{
	global $config;
	$connection = get_connection();
	$result =  mysql_query($sql);
	if ($result === FALSE)
	{
		$output = FALSE;
		echo mysql_error();
	}
	else
	{
		$output = $result;
	}
	mysql_close($connection);
	return $output;
}

function execute_insert_query($sql)
{
	global $config;
	$connection = get_connection();
	$result = mysql_query($sql);
	if ($result === FALSE)
	{
		$output = FALSE;
		echo mysql_error();
	}
	else
	{
		$output = mysql_insert_id();
	}
	mysql_close($connection);
	return $output;
}

function get_process_timeout()
{
	global $config;
	return $config['db']['process_timeout'];
}
?>
